// Tutorial 3 - prototype

// function to call the server
function callServer() {
  new Ajax.Request(
    "http://www.cs.cityu.edu.hk/~cs4380/webservice/exchange/hkd2usd.cgi",
    {method: "get", 
     parameters: { hkd: $F("hkd") },
     onSuccess:
       function(transport) {
         var usd = transport.responseText;
         $("usd").update("HK$" + $F("hkd") + " = US$" + usd);
       },
     onCreate:
       function(resp) {
         $("usd").update("calculating...");
       } 
    }
  );
} 

// setup javascript calls unobstrusively
function setup() {
  var e = $("hkd");
  e.onkeyup=callServer;
}

window.onload = setup;
